<template>
  <div id="app-main">
    <el-row>
      <el-col :span="12">
        <div>
          <Task title="运营人员（当天）" class="bg1" :list="taskReportList[0]">
            <template
              #default="{
                list: { total, completedTotal, cancelTotal, workerCount }
              }"
            >
              <TaskItem label="工单总数（个）" :total="total" />
              <TaskItem label="完成工单（个）" :total="completedTotal" />
              <TaskItem label="拒绝工单（个）" :total="cancelTotal" />
              <TaskItem label="运营人员数（个）" :total="workerCount" />
            </template>
          </Task>
        </div>
      </el-col>
      <el-col :span="12">
        <div>
          <Task title="运维人员（当天）" class="bg2" :list="taskReportList[1]">
            <template
              #default="{
                list: { total, completedTotal, cancelTotal, workerCount }
              }"
            >
              <TaskItem label="工单总数（个）" :total="total" />
              <TaskItem label="完成工单（个）" :total="completedTotal" />
              <TaskItem label="拒绝工单（个）" :total="cancelTotal" />
              <TaskItem label="运营人员数（个）" :total="workerCount" />
            </template>
          </Task>
        </div>
      </el-col>
    </el-row>
    <el-row class="bottom">
      <el-col :span="18">
        <div class="user-task-rank">
          <Task title="工单状态" :data="{}">
            <div slot="tool" class="tool">
              <el-date-picker
                v-model="date"
                type="daterange"
                range-separator="~"
                :start-placeholder="start.slice(0, 10)"
                :end-placeholder="end.slice(0, 10)"
              />
              <div class="week-month-year" v-active>
                <div class="item is-checked" @click="checkoutWeek">周</div>
                <div class="item" @click="checkoutMonth">月</div>
                <div class="item" @click="checkoutYear">年</div>
              </div>
            </div>
          </Task>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="user-task-rank">
          <Task title="人效排名（月度)">
            <div slot="tool" class="tool">
              <el-select v-model="value" placeholder="请选择">
                <el-option
                  v-for="item in regionList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </div>
            <div class="week-month-year" v-active slot="subtool">
              <div class="item is-checked">运营人员</div>
              <div class="item">运维人员</div>
            </div>
          </Task>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import Task from '@/components/task.vue'
import TaskItem from '@/components/task-item'
import moment from 'moment'
import { taskReportInfo } from '@/api/work'
import { areaList } from '@/api/people-admin'
export default {
  name: 'census-page',
  components: {
    Task,
    TaskItem
  },
  props: {},
  data() {
    return {
      // 开始日期
      start: '',
      // 结束日期
      end: '',
      // 任务汇报单
      taskReportList: [],
      date: '',
      value: '',
      regionList: []
    }
  },
  computed: {},
  watch: {},
  methods: {
    setStart() {
      this.start = moment().weekday(1).format('YYYY-MM-DD 00:00:00')
    },
    setEnd() {
      this.end = moment().format('YYYY-MM-DD 23:59:59')
    },
    // 工单信息
    async getTaskReportInfo() {
      const res = await taskReportInfo(this.start, this.end)
      this.taskReportList = res
    },
    // 获取区域列表
    async getAreaList() {
      const res = await areaList()
      this.regionList = res.currentPageRecords
    },
    checkoutWeek() {
      this.start = moment().weekday(1).format('YYYY-MM-DD 00:00:00')
    },
    checkoutMonth() {
      this.start = moment().format('YYYY-MM-01 00:00:00')
    },
    checkoutYear() {
      this.start = moment().format('YYYY-01-01 00:00:00')
    }
  },
  created() {
    this.setStart()
    this.setEnd()
    this.getTaskReportInfo()
    this.getAreaList()
  }
}
</script>

<style scoped lang="scss">
#app-main {
  background-color: #f8fafd;
}
.el-row {
  margin-left: -10px;
  margin-right: -10px;
  .el-col {
    padding-left: 10px;
    padding-right: 10px;
  }
}

.bg2 {
  background: #fbefe8
    url('http://likede2-admin.itheima.net/img/operation.4120cc58.png') no-repeat
    repeat calc(100% - 12px) 100%;
}
.bg1 {
  background-color: #e9f3ff;
  background-image: url(),
    url();
  background-repeat: no-repeat, no-repeat;
  background-position: 0 0, calc(100% - 12px) 100%;
}
.user-task-rank {
  min-height: 542px;
  margin-top: 20px;
  display: flex;
  .content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
}
.tool {
  display: flex;
  .el-range-editor {
    width: 230px;
    margin-right: 21px;
    height: 32px;
  }
}
.week-month-year {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 34px;
  background: rgba(233, 243, 255, 0.37);
  border-radius: 10px;
  padding: 0 5px;
  .item {
    height: 25px;
    padding: 0 12px;
    font-size: 14px;
    color: #9ca3b4;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
  }
  .item.is-checked {
    background: #fff;
    box-shadow: 0 0 4px 0 rgb(0 0 0 / 11%);
    border-radius: 7px;
    font-weight: 600;
    color: #333;
  }
}
.el-select {
  width: 88px;
  font-size: 13px;
  ::v-deep .el-input__inner {
    height: 32px;
    line-height: 32px;
    .el-input__inner {
      top: 5px;
    }
  }
}
</style>
